package com.example.login.Service;

import com.example.login.Mapper.CartMap;
import com.example.login.Mapper.GoodsMap;
import com.example.login.Pojo.Cart;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Service("CartService")
public class CartService {
    @Autowired
    GoodsMap goodsMap;
    @Autowired
    CartMap cartMap;
    public void insert(int user_id,int goods_id,String sku_code,String addtime,int num,String store_name){
        ArrayList<Cart> cart=cartMap.getCartById(user_id,goods_id);
        if(cart.size()==0)
        cartMap.AddCart(user_id,goods_id,sku_code,addtime,num,store_name);
        else
            {
                int tempNum=cartMap.getNumById(user_id,goods_id)+1;
                cartMap.Update(tempNum,user_id,goods_id);
            }
    }
}
